package com.xju.controller.book;

import com.xju.common.utils.JSONUtil;
import com.xju.common.utils.JdbcUtils;
import com.xju.service.BookService;
import com.xju.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/book/insert")
public class BookInsertServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取参数
        req.setCharacterEncoding("utf-8");
        //获取bookID
        String bookID = req.getParameter("bookID");
        String title = req.getParameter("Title");
        String authorName = req.getParameter("AuthorName");
        String isbn = req.getParameter("ISBN");
        String publisher = req.getParameter("Publisher");
        String publicationDate = req.getParameter("PublicationDate");
        String flag = req.getParameter("flag");

        BookService bookService =new BookServiceImpl();
        //调用service
        if(bookID==null||bookID.trim().isEmpty()){
            //添加操作
            bookService.insert(title,authorName,isbn,publisher,publicationDate,flag);
        }
        else{
            //更新操作
            bookService.updataByBookID(bookID,title, authorName ,isbn,publisher,publicationDate,flag);
        }


        JSONUtil.printByJSON(resp,true);

    }
}
